package com.evil.common.application.dto.judge;

import cn.hutool.core.bean.BeanUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;

import javax.validation.Valid;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 或条件实体
 *
 * @author liyang
 * @date 2022-08-08 00:00
 */
@Data
@EqualsAndHashCode(callSuper = true)
public class JudgeOr extends Judge {

    public static String sign = " || ";

    /**
     * 且条件列表
     */
    @Valid
    private List<JudgeAnd> judgeAnd;

    public JudgeOr() {
        this.judgeAnd = new ArrayList<>();
    }

    public JudgeOr(List<JudgeAnd> judgeAnd) {
        this.judgeAnd = judgeAnd;
    }

    public JudgeOr copy() {
        JudgeOr judgeOr = BeanUtil.copyProperties(this, JudgeOr.class);
        judgeOr.setJudgeAnd(JudgeAnd.copy(this.judgeAnd));
        return judgeOr;
    }

    public static List<JudgeOr> copy(Collection<JudgeOr> ors) {
        return ors.stream().map(e -> e.copy()).collect(Collectors.toList());
    }
}
